<template>
	<div class="container">
		<Header title="选择楼盘"></Header>
		<ul class="items-list">
			<li v-for="(item,index) in options" @click="checkedState(item)">
				<span class="img"></span>
				<p class="text">{{item.name}}</p>
				<i class="checkIcon" :class="{'active':item.isShow}"></i>
				<input type="checkbox" class="mint-checkbox-input" v-model="item.isShow">
			</li>
		</ul>
	</div>
</template>
<script>
	import { Toast } from 'mint-ui'
	export default {
		data () {
		    return {
		    	options:[],
		    	premisesId: window.sessionStorage.getItem(this.utilHelper.appAssistant+"_premisesId")
		    }
		},
		mounted: function() {
	       this.initPremisesList();
		}, 
		methods :{
			checkedState (item) {
			    const appAssistant = this.utilHelper.appAssistant;
				// this.options[index].isShow = !this.options[index].isShow;
				this.options.forEach(function(options,index){
					options.isShow = false;
				})
				item.isShow = true;
				window.sessionStorage.setItem(appAssistant+"_premisesId", item.id);
				window.sessionStorage.setItem(appAssistant+"_premisesName", item.name);
			  	this.$router.push({path: '/assistantIndex'});
			},
			initPremisesList() {
				var _self = this;
				var body = {};
				body.params = {};
				var url = _self.utilHelper.apiUrl+'/api/getCaseMemberList';
				_self.$http.post(url, body).then((response)=>{
					var body = response.body;
					if(body.result==1){
						body.resData.caseMemberList.forEach(function(item,index){
							if(item.premisesId == _self.premisesId){
								_self.options.push({
									name:body.resData.caseMemberList[index].premisesName,
					             	id:body.resData.caseMemberList[index].premisesId,
					             	isShow:true
								})
							}else{
								_self.options.push({
									name:body.resData.caseMemberList[index].premisesName,
					             	id:body.resData.caseMemberList[index].premisesId,
					             	isShow:false
								})
							}
						})
					}else{
						Toast({
						  	message: '数据获取失败',
						  	position: 'middle',
						  	duration: 2000
						});
					}
				});
			}
		}
	}
</script>
<style scoped>
	.items-list{background-color: #fff;}
	.items-list li{height: 42px;line-height: 42px;padding: 0 30px 0 36px;width: 100%;position: relative;border-bottom: 1px solid #cdcdcd;}
	.items-list .img{position: absolute;left: 10px;top: 14px;width: 14px;height: 14px;background:url(../../assets/images/checkImg.png) no-repeat;background-size: 14px auto;}

	.items-list .text{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color: #333;}
	.checkIcon{position: absolute;right: 10px;width: 18px;height: 18px;background:url(../../assets/images/checked.png) no-repeat;background-position: 0 0;background-size: 36px auto;top: 12px;}
	.checkIcon.active{background-position: -18px 0;}
</style>